function fillEngineTableWIX(link, language, itemId) {
    if ((!link) || (!language)) {
        return;
    }   //if
    $('#engineTable').html('');
    $('#filtersTable').html('');
    $('#filterDetails').html('');
    $('#filter-buttons-id').hide();
    $('#engineLoaderId').show();
    $.ajax({
        method: "POST",
        url: link,
        data: { masterItemId: itemId, languageName: language }
    })
    .fail(function(response) {
        $('#engineLoaderId').hide();
    })
    .done(function(response) {
        $('#engineLoaderId').hide();        
        $('#engineTable').html(response);
    });
}

function fillFilterTableWIX(link, language, modelId, engineId) {
    if ((!link) || (!language)) {
        return;
    }   //if
    $('#filtersTable').html('');
    $('#filterDetails').html('');
    $('#filter-buttons-id').hide();
    $('#filtersLoader').show();
    $.ajax({
        method: "POST",
        url: link,
        data: { engineId: engineId, modelId: modelId, languageName: language }
    })
    .fail(function(response) {
        $('#filtersLoader').hide();
    })
    .done(function(response) {
        $('#filtersLoader').hide();
        $('#filtersTable').html(response);
    });
}

function fillFilterDetails(link, language, filterId, assetsPrefix) {
    if ((!link) || (!language)) {
        return;
    }   //if
    $('#filterDetails').html('');
    $('#filterDetailsLoader').show();
    $.ajax({
        method: "POST",
        url: link,
        data: { filterId: filterId, languageName: language }
    })
    .fail(function(response) {
        $('#filterDetailsLoader').hide();
        $('#filter-buttons-id').hide();
    })
    .done(function(response) {
        $('#filterDetailsLoader').hide();
        $('#filterDetails').html(response);
        $('#filter-buttons-id').show();
        var isContainer = $("#container360").length;
        var isContainerFull = $("#container360fullscreen").length;
        if (isContainer) {
            var filterNumber = $("#container360").data("number");
            var filterDir = $("#container360").data("number");
            var items = filterNumber.split(";");
            var count = items.length;
            if (count > 1) {
                filterNumber = items[1];
                filterDir = items[0];
            }
            // hide URL field on the iPhone/iPod touch
            function hideUrlBar() {
            }

            var icon_localisation = assetsPrefix + "/icons/";

            icon_localisation = icon_localisation.substr(1);
            console.log(icon_localisation);
            // create the object player with the container

            obj = new object2vrPlayer("container360");
            // add the skin object
            skin = new object2vrSkin(obj, "Content/Assets/Filters/icons/");
            // load the configuration

            $(skin._tt_zoomin).find('div').not('.ggskin_text').html(getTranslation('gg_skin_zoomin', language));
            $(skin._tt_zoomout).find('div').not('.ggskin_text').html(getTranslation('gg_skin_zoomout', language));
            $(skin._tt_autorotate).find('div').not('.ggskin_text').html(getTranslation('gg_skin_autorotate', language));
            $(skin._tt_info).find('div').not('.ggskin_text').html(getTranslation('gg_skin_info', language));
            $(skin._tt_fullscreen).find('div').not('.ggskin_text').html(getTranslation('gg_skin_fullscreen', language));

            skin._info.onclick = function() {
                $(".logistic-modal").click();
            }

            var xml_file = "/Content/Assets/Filters/WL7499/WL7499_out.xml";

            var indv_xml_file = assetsPrefix + "/" + filterDir + "/0750/" + filterNumber + "_out.xml";
            //var indv_xml_file = assetsPrefix + "/" + filterNumber + "/0750/3648_out.xml";

            obj.readConfigUrl(indv_xml_file);
            // hide the URL bar on the iPhone
            setTimeout(function() { hideUrlBar(); }, 10);
            //$("#360containertemp").appendTo("#360container");
            var wid = $("#container360").width();
            var hei = Math.round(wid * 2 / 3, 2);
            //console.log(hei);
            $("#container360").css("height", hei);
            $("img.ggskin.ggskin_svg").each(function() {
                var src = $(this).attr('src');
                src = src.replace('svg', 'png');
                $(this).attr('src', src);
            });

            //$("div.under-360-gallery").append("<div class='nav_bar2'></div>");
            $("#container360 div div").each(function() {
                if ($(this).children(".ggskin_container").length > 0) {
                    $(this).addClass('overVisible');
                }
            });
            $("div.ggskin.ggskin_container").addClass("nav_bar");
            $("div.ggskin.ggskin_container").css({ "top": "0", "bottom": "-50px;" });


            // initSpinner(assetsPrefix + '/WA6702/');
            // initSpinner2(assetsPrefix + '/WA6214/');


            if (isContainerFull) {
                objFullscreen = new object2vrPlayer("container360fullscreen");

                skin._fullscreen.onclick = function() {
                    objFullscreen.toggleFullscreen();
                    $('#container360fullscreen').css('display', 'block');
                }
                isfullscreen = false;
                function checkFullscreen() {
                    if (
                        document.fullscreenElement ||
                        document.webkitFullscreenElement ||
                        document.mozFullScreenElement ||
                        document.msFullscreenElement
                    ) {
                        isfullscreen = true;

                    } else {
                        $('#container360fullscreen').css('display', 'none');
                        isfullscreen = false;
                    }
                }
                document.addEventListener('webkitfullscreenchange', function() { checkFullscreen(); }, false);
                document.addEventListener('mozfullscreenchange', function() { checkFullscreen(); }, false);
                document.addEventListener('fullscreenchange', function() { checkFullscreen(); }, false);
                document.addEventListener('MSFullscreenChange', function() { checkFullscreen(); }, false);

                var indv_full_xml_file = assetsPrefix + "/" + filterDir + "/1500/" + filterNumber + "_out.xml";

                objFullscreen.readConfigUrl(indv_full_xml_file);
                var fullscreenWidth = screen.width;
                var fullscreenHeight = screen.height;
                $("#container360fullscreen").width(fullscreenWidth);
                $("#container360fullscreen").height(fullscreenHeight);
            } else {
                skin._fullscreen.onclick = function() {
                }
                $(skin._fullscreen).hide();
            }
        }

    });
}

function clearTablesData() {
    $('#engineTable').html('');
    $('#filtersTable').html('');
    $('#filterDetails').html('');
    $('#filter-buttons-id').hide();
}

function initSpinner(assetsLink) {
    if (!assetsLink) {
        return;
    }   //if
    var filter = $('.car').ThreeSixty({
        totalFrames: 52, // Total no. of image you have for 360 slider
        endFrame: 52, // end frame for the auto spin animation
        currentFrame: 1, // This the start frame for auto spin
        imgList: '.threesixty_images', // selector for image list
        progress: '.spinner', // selector to show the loading progress
        imagePath: assetsLink, // path of the image assets
        filePrefix: '', // file prefix if any
        ext: '.jpg', // extention for the assets
        height: 640,
        width: 426,
        navigation: true,
        responsive: true
    });
    $('.custom_previous').bind('click', function(e) {
        filter.previous();
    });

    $('.custom_next').bind('click', function(e) {
        filter.next();
    });

    $('.custom_play').bind('click', function(e) {
        filter.play();
    });

    $('.custom_stop').bind('click', function(e) {
        filter.stop();
    });


}

function initSpinner2(assetsLink) {
    if (!assetsLink) {
        return;
    }   //if
    var filter = $('.car2').ThreeSixty({
        totalFrames: 52, // Total no. of image you have for 360 slider
        endFrame: 52, // end frame for the auto spin animation
        currentFrame: 1, // This the start frame for auto spin
        imgList: '#threesixty_images2', // selector for image list
        progress: '.spinner', // selector to show the loading progress
        imagePath: assetsLink, // path of the image assets
        filePrefix: '', // file prefix if any
        ext: '.jpg', // extention for the assets
        height: 800,
        width: 1000,
        navigation: true,
        responsive: true
       
    });
    $('.custom_previous').bind('click', function(e) {
        filter.previous();
    });

    $('.custom_next').bind('click', function(e) {
        filter.next();
    });

    $('.custom_play').bind('click', function(e) {
        filter.play();
    });

    $('.custom_stop').bind('click', function(e) {
        filter.stop();
    });


}
